package com.suray.rgv.son.core;

import com.suray.rgv.son.util.RgvSonActionResult;
import com.suray.rgv.son.util.RgvSonParamUtil;
import com.suray.rgv.son.util.RgvSonStatus;
import com.suray.type.RgvSonTaskResult;
import com.suray.type.RgvSonTaskStatus;
import com.suray.rgv.util.ErrorInfo;
import com.suray.wcs.res.enums.PalletStatus;

/**
 * 子车数据
 */
public class RgvSonInfo {

    //数据更新时间
    protected long time;

    //行驶加速度：700
    protected float runAcc;

    //行驶减速度700
    protected float runDec;

    //行驶速度2700
    protected float runSpeed;

    //行驶加速度：700
    protected float runSpeedMoveAcc;

    //行驶减速度700
    protected float runSpeedMoveDec;

    //行驶速度2700
    protected float runSpeedMove;

    //升降加速度：2000
    protected float upDownAcc;

    //升降减速度2000
    protected float upDownDec;

    //升降速度：2700
    protected float upDownSpeed;

    /**
     * 平台位置条码
     */
    protected String platformGroundCode;

    /**
     * 小车方向
     * x增大方向
     * 为右：true
     * 为左：false
     */
    protected Boolean rgvDirectionX;

    /**
     * 小车方向
     * y增大方向
     * 为右：true
     * 为左：false
     */
    protected Boolean rgvDirectionY;

    /**
     * 序列号
     */
    protected String series;

    /**
     * 小车状态
     */
    protected RgvSonStatus rgvStatus;

    /**
     * 小车就绪状态
     */
    protected RgvSonStatus rgvReadyStatus;

    /**
     * 是否充电中
     */
    protected Boolean isCharge;

    /**
     * 是否按速度行驶
     */
    protected Boolean isSpeedMode;

    /**
     * 托盘状态
     */
    protected PalletStatus palletStatus;

    /**
     * 动作命令号
     */
    protected Integer actNo;

    /**
     * 动作结果
     */
    protected RgvSonActionResult actionResult;

    /**
     * 当前行驶速度rpm
     */
    protected Integer curSpeed;

    /**
     * 当前条码
     */
    protected String groundCode;

    /**
     * 小车行驶位移数值
     */
    protected Long moveDistance;

    /**
     * 换向电机编码器数值
     */
    protected Long codeNum;

    /**
     * 异常信息
     */
    protected ErrorInfo errorInfo;

    /**
     * 错误信息
     */
    protected int errorCode;

    /**
     * 报警信息
     */
    protected int warnCode;

    /**
     * 小车电量
     */
    protected Integer soc;

    /*********************************************任务信息***********************************************/

    /**
     * 任务执行状态
     */
    protected RgvSonTaskStatus taskStatus;

    /**
     * 任务编号
     */
    protected Integer taskId;

    /**
     * 已完成的节点序号
     */
    protected Integer finishSegment;

    /**
     * 动作执行结果
     */
    protected RgvSonTaskResult taskResult;

    /**
     * 任务错误信息
     */
    protected int taskErrorCode;

    /*****************************************************************************************************/

    /**
     * 车辆是否启用
     */
    protected boolean rgvEnable;

    public RgvSonInfo(String serialNum) {
        this.series = serialNum;
        this.rgvStatus = RgvSonStatus.INVALID;
        this.actionResult = RgvSonActionResult.INVALID;
        this.palletStatus = PalletStatus.UNKNOWN;
        this.groundCode = "";
        this.soc = -1;
        this.actNo = 0;
        this.curSpeed = 0;
        this.time = 0;
        this.rgvEnable = true;

        runAcc = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_RUN_ACC);
        runDec = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_RUN_DEC);
        runSpeed = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_RUN_SPEED);
        runSpeedMoveAcc = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_RUN_SPEED_MOVE_ACC);
        runSpeedMoveDec = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_RUN_SPEED_MOVE_DEC);
        runSpeedMove = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_RUN_SPEED_MOVE);
        upDownAcc = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_UP_DOWN_ACC);
        upDownDec = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_UP_DOWN_DEC);
        upDownSpeed = changeRpmToSpeed(RgvSonParamUtil.RGV_SON_UP_DOWN_SPEED);

        taskStatus = RgvSonTaskStatus.INVALID;
        taskResult = RgvSonTaskResult.INVALID;
    }

    private float changeRpmToSpeed(float rpm) {
        return rpm * RgvSonParamUtil.RGV_SON_RPM_FACT;
    }

    public String getSeries() {
        return series;
    }

    public RgvSonStatus getRgvStatus() {
        return rgvStatus;
    }

    public Integer getActNo() {
        return actNo;
    }

    public RgvSonActionResult getActionResult() {
        return actionResult;
    }

    public float getCurSpeed() {
        return changeRpmToSpeed(curSpeed);
    }

    public Integer getCurSpeedRpm() {
        return curSpeed;
    }

    public String getGroundCode() {
        return groundCode;
    }

    public Long getMoveDistance() {
        return moveDistance;
    }

    public Long getCodeNum() {
        return codeNum;
    }

    public ErrorInfo getErrorInfo() {
        return errorInfo;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public int getWarnCode() {
        return warnCode;
    }

    public Integer getSoc() {
        return soc;
    }

    public float getRunAcc() {
        return runAcc;
    }

    public float getRunDec() {
        return runDec;
    }

    public float getRunSpeed() {
        return runSpeed;
    }

    public float getRunSpeedMoveAcc() {
        return runSpeedMoveAcc;
    }

    public float getRunSpeedMoveDec() {
        return runSpeedMoveDec;
    }

    public float getRunSpeedMove() {
        return runSpeedMove;
    }

    public float getUpDownAcc() {
        return upDownAcc;
    }

    public float getUpDownDec() {
        return upDownDec;
    }

    public float getUpDownSpeed() {
        return upDownSpeed;
    }

    public String getPlatformGroundCode() {
        return platformGroundCode;
    }

    public RgvSonTaskStatus getTaskStatus() {
        return taskStatus;
    }

    public Integer getTaskId() {
        return taskId;
    }

    public Integer getFinishSegment() {
        return finishSegment;
    }

    public RgvSonTaskResult getTaskResult() {
        return taskResult;
    }

    public Integer getTaskErrorCode() {
        return taskErrorCode;
    }

    public Long getTime() {
        return time;
    }
}
